# Maintainer: Felix Yan <felixonmars@archlinux.org>
# Maintainer: Caleb Maclennan <caleb@alerque.com>

pkgname=python-cmarkgfm
_pyname=${pkgname#python-}
pkgver=2022.10.27
pkgrel=4
pkgdesc="Minimal bindings to GitHub's fork of cmark"
url="https://github.com/theacodes/cmarkgfm"
license=('MIT')
arch=('loong64' 'x86_64')
depends=('cmark-gfm' 'python-cffi')
makedepends=('cmark-gfm' 'cython' 'python-build' 'python-installer' 'python-setuptools' 'python-cffi' 'python-wheel')
checkdepends=('python-pytest')
# Upstream did not tag the version on GitHub to match PyPi, see https://github.com/theacodes/cmarkgfm/issues/51
# source=("https://github.com/theacodes/cmarkgfm/archive/$pkgver/$pkgname-$pkgver.tar.gz")
source=("https://files.pythonhosted.org/packages/source/${_pyname::1}/$_pyname/$_pyname-$pkgver.tar.gz")
sha512sums=('b5c1c622a7df9eb882bf152d98baeb61e9103f7683ec5d50e3eee1ada7caac2daf4e1e1e8c34566ab8c8e00136da9e65ae356e06e511da281b8de890aca85a86')

prepare() {
  cd cmarkgfm-$pkgver
  sed -e '/include_dirs=/a libraries=["cmark-gfm", "cmark-gfm-extensions"],' \
      -i src/cmarkgfm/build_cmark.py
}

build() {
  cd cmarkgfm-$pkgver
  python -m build -wn
}

check() {
  cd cmarkgfm-$pkgver
  local _pyver=cpython-$(python -c 'import sys; print("".join(map(str, sys.version_info[:2])))')
  PYTHONPATH="$PWD/build/lib.linux-$CARCH-${_pyver}" pytest
}

package() {
  cd cmarkgfm-$pkgver
  python -m installer -d "$pkgdir" dist/*.whl
  install -Dm0644 -t "$pkgdir"/usr/share/licenses/$pkgname/ LICENSE.txt
}
